package com.zqh.orderquery.controller;

import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.vo.OrdersVO;
import com.zqh.orderquery.service.OrderQueryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-02-18 2:15
 */
@RestController
@RequestMapping("order")
public class OrderQueryController{
    @Resource
    private OrderQueryService orderQueryService;

    /**
     * 功能描述:
     * 超时未支付检查服务调用，查看订单状态
     *
     * @param id
     * @return com.zqh.myfmmall.result.Result
     * @author kono曾淇杭哒！
     * @date 2022/3/8 14:44
     */
    @GetMapping("getStatusById/{id}")
    public Result getStatusById(@PathVariable("id") String id){

        return Result.success(orderQueryService.getOrderStatus(id));
    }

    /**
     * 功能描述:
     *  接口服务调用，分页查询用户某状态的订单vo
     *
     * @param pageNum
     * @param pageSize
     * @param status
     * @param uId
     * @return com.zqh.myfmmall.result.Result
     * @author kono曾淇杭哒！
     * @date 2022/3/8 14:45
     */
    @GetMapping("pageByStatus/{pageNum}/{pageSize}/{status}/{uId}")
    public Result pageByStatus(@PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize,
                       @PathVariable("status") Integer status,
                       @PathVariable("uId") String uId){

        List<OrdersVO> ordersVOS = orderQueryService.pageByStatus(uId, status, pageSize, pageNum);
        return Result.success(ordersVOS);
    }

    /**
     * 功能描述:
     * 接口调用，查询用户各状态订单的数量
     *
     * @param uId
     * @return com.zqh.myfmmall.result.Result
     * @author kono曾淇杭哒！
     * @date 2022/3/8 14:48
     */
    @GetMapping("counts/{uId}")
    public Result counts(@PathVariable("uId") String uId){
        Map<String, Object> countsMap = orderQueryService.orderCounts(uId);
        return Result.success(countsMap);
    }
}
